import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

import '../../theme/jr.dart';

// ignore: must_be_immutable
class JREmptyView extends StatelessWidget {
  final String? imageFile;
  final ErrorType? errorType;
  final ColorType? colorType;
  final VoidCallback? onTap;
  String? desc;
  final Size imgSize;

  JREmptyView(
      {super.key,
      this.errorType = ErrorType.noData,
      String? desc,
      this.colorType = ColorType.white,
      this.imageFile,
      this.onTap,
      this.imgSize = const Size(240, 160)}) {
    this.desc = desc ?? "没有数据";
  }

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: onTap,
      child: Container(
        alignment: Alignment.center,
        padding: const EdgeInsetsDirectional.symmetric(vertical: 12),
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            imgWidget(),
            if (desc != null && desc!.isNotEmpty)
              Padding(
                padding: const EdgeInsetsDirectional.only(top: 6),
                child: Text(
                  desc!,
                  textAlign: TextAlign.center,
                  // style: JRTextStyles.styleFont12W400
                  //     .copyWith(color: JR.color.subText),
                ),
              )
          ],
        ),
      ),
    );
  }

  Widget imgWidget() {
    String imageFile = "";
    if (errorType == ErrorType.noData) {
      imageFile = colorType == ColorType.white
          ? "assets/images/home/no_data.png"
          : "assets/images/seat_no_data_black.webp";
    } else if (errorType == ErrorType.noNetwork) {
      imageFile = colorType == ColorType.white
          ? "assets/images/seat_no_network.webp"
          : "assets/images/seat_no_network_black.webp";
    } else if (errorType == ErrorType.noSearch) {
      imageFile = colorType == ColorType.white
          ? "assets/images/seat_no_search.webp"
          : "assets/images/seat_no_search_black.webp";
    } else if (errorType == ErrorType.noMessage) {
      imageFile = colorType == ColorType.white
          ? "assets/images/seat_no_message.webp"
          : "assets/images/seat_no_message_black.webp";
    } else {
      imageFile = colorType == ColorType.white
          ? "assets/images/home/no_data.png"
          : "assets/images/seat_no_data_black.webp";
    }
    return SizedBox(
      width: imgSize.width,
      height: imgSize.height,
      child: JR.img(imageFile, width: imgSize.width, height: imgSize.height),
    );
  }
}

/// 错误类型
enum ErrorType {
  noData,

  /// 无数据
  noNetwork,

  /// wifi图片
  noMessage,

  /// 无消息图片
  noSearch,

  /// 搜索图片
}

/// 白背景 黑背景
enum ColorType { white, black }
